<template>
	<view class="wrap bgw">
		<view class="topsMy "> 
			<view @tap="checkingUser()" class="top_user p30">
				<image class="userImg" :src="data.avatarImg" mode=""></image>
				<view class="userTxt">
					<p class="p1 one">
						{{data.name}}
					</p>
					<p class="p2 one">
						{{data.mobile}}
					</p>
				</view>
				<view  v-if="token" @tap.stop @tap="Go('../users/users')" class="userLabel">
					个人主页
				</view>
			</view>
			<view class="nav">
				<view @tap="Go('../Collection/Collection')">
					<p> {{data.productFavoriteQuantity}}</p>
					收藏
				</view>
				<view @tap="Go('../track/track')">
					<p> {{data.historyQuantity}}</p>
					足迹
				</view>
				<view @tap="Go('../fans/fans?state=0')">
					<p> {{data.followQuantity}}</p>
					关注
				</view>
				<view @tap="Go('../fans/fans?state=1')">
					<p>{{data.fansQuantity}}</p>
					粉丝
				</view> 
			</view>
			<view class="p30">
				<view @tap="Go('../MyNews/MyNews')" class="strip">
					<image src="../../static/image/icon_xiaoxi@2x.png" mode=""></image>

					<!-- <image class="icons vm" src="../../static/my/icon_xiaoxi@2x.png" mode=""></image>
					点击进入消息中心
					<image class="go vm" src="../../static/my/icon_xia@2x.png" mode=""></image> -->
				</view>
			</view>
		</view>
		<view class="content ">
			<p class="title p30">
				我是卖家
			</p>
			<view class="navs">
				<view @tap="Go('../myProducts/myProducts')">
					<image src="../../static/my/icon_fabu@2x.png" mode=""></image>
					我发布的
				</view>
				<view @tap="Go('../sell/sell?state=RESERVED')">
					<image src="../../static/my/yuding.png" mode=""></image>
					已预订的
					<span v-if="countReserveds.sellQuantity" class="icons">
						{{countReserveds.sellQuantity}}
					</span>
				</view> 
				<view @tap="Go('../sell/sell')">
					<image src="../../static/my/icon_maichude@2x.png" mode=""></image>
					我卖出的 
				</view> 
			</view>
			<p class="title p30">
				我是买家
			</p>
			<view class="navs">
				<view @tap="Go('../buy/buy?state=RESERVED')">
					<image src="../../static/my/yuiding.png" mode=""></image>
					我预定的
					<span v-if="countReserveds.buyQuantity" class="icons">
						{{countReserveds.buyQuantity}}
					</span>
				</view> 
				<view @tap="Go('../buy/buy')">
					<image src="../../static/my/icon_maidaode@2x.png" mode=""></image>
					我买到的 
				</view> 
				<view @tap="Go('../buy/buy?state=DELIVERED')">
					<image src="../../static/my/icon_pingjia.png" mode=""></image>
					待评价的 
				</view> 
			</view>
			<p class="title p30">
				其他工具
			</p>
			<view class="navs navs2">
				<view @tap="Go('../MarketList/MarketList')">
					<image src="../../static/my/icon_jishi@2x.png" mode=""></image>
					创建的集市
				</view>
				<view @tap="Go('../addressList/addressList')">
					<image src="../../static/my/icon_dizhi.png" mode=""></image>
					我的地址
				</view>
				<view v-if="isStore == false" @tap="Go('../CreateShop/CreateShop')">
					<image src="../../static/my/kaidian.png" mode=""></image>
					我要开店
				</view>
				<view  v-if="isStore == true" @tap="Go('../shopSet/shopSet')">
					<image src="../../static/my/guanli.png" mode=""></image>
					店铺管理
				</view>
			</view>
		</view>
		<empower ref='empowerfn'></empower>
		<newlyBuild ref="newlyBuild"></newlyBuild>
	</view>
</template>

<script>
	import {
		userInfo,countReserved
	} from '../../api/api.js'
	import {toLogin,checkingLogin} from '@/tool/index.js'
	export default {
		data() {
			return {
				token:false, 
				isStore:-1,
				data: {
					avatarImg: require('../../static/image/userImgs.png'),
					name: '未登录',
					productFavoriteQuantity:0,
					historyQuantity:0,
					followQuantity:0, 
					fansQuantity:0
				},
				countReserveds:{}
			}
		},
		onLoad() {
			uni.onTabBarMidButtonTap(() => {
				this.$refs['newlyBuild'].show() 
			}) 
			
		},
		onShow() { 
			this.checkingLogins() 
		},
		methods: {  
			async checkingLogins(){
				let checking =await checkingLogin()  
				if(checking){
					this.token = true
					this.init()
				}
			},
			checkingUser(){ 
				if(!this.token){
					toLogin()
				} 
			},
			async init() {
				let data = await userInfo()
				this.data = data.data
				this.isStore = data.data.isStore
				 let countReserveds = await countReserved()
				 this.countReserveds = countReserveds.data
			},
			aaa() {
				this.$refs['empowerfn'].show()
			},
			Go(url) {  
				if (!this.token) {
					toLogin()
					return
				} else {
					this.$navigateTo(url)
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	@import './index.less';
</style>
